﻿using BLL;
using IBLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsFormsApp1;

namespace 考试管理系统
{
    public partial class FrmLogin : Form
    {
        ILogin_IBLL login=new Login_BLL();
         public string s = null;
        public static string UseName = null;
        public bool s1 = false;
        public FrmLogin()
        {
            InitializeComponent();
           
        }
        #region 自定义控件
      
        #endregion
        #region 关闭窗口
        private void button7_Click_1(object sender, EventArgs e)
        {
            Application.Exit();
        }
        #endregion
        #region 登录验证
        private void Login_Click(object sender, EventArgs e)
        {
            #region 非空约束
            if (txtAccount.Text.Trim()==null&&txtAccount.Text.Trim()=="")
            {
                MessageBox.Show("请检查账号输入是否正确","登录提示",MessageBoxButtons.OK,MessageBoxIcon.Question);
                return;
            }
            if (txtPwd.Text.Trim()==null&&txtPwd.Text.Trim()=="")
            {
                MessageBox.Show("请检查密码输入是否正确", "登录提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
                return;
            }
            UseName = radioButton3.Checked == true ? "管理员" : radioButton2.Checked == true ? "学生" : "老师";
            s = login.IsLogin(txtAccount.Text,txtPwd.Text,UseName);
            if (s!=null)
            {
                if (s1)
                {
                    Interchange.k(UseName);
                }
                else
                {
                    
                }
                this.DialogResult = DialogResult.OK;

                // MessageBox.Show("登录成功", "登录提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            }
            else
            {
                MessageBox.Show("账号或密码错误,请重新登录", "登录提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
            }
            
            #endregion
        }
        #endregion
        #region 拖动窗口
        Point point;
        bool od;
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            point = e.Location;
            od = true;
        }

        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {

            od = false;
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {

            if (od)
            {
                Point point1 = Control.MousePosition;
                point1.Offset(-point.X, -point.Y);
                this.Location = point1;
            }
        }
        #endregion
        #region 获取焦点
        private void txtAccount_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue==13)
            {
                txtPwd.Focus();
            }
        }

        private void txtPwd_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                Login_Click(null, null);
                
            }
        }
        private void FrmLogin_Load(object sender, EventArgs e)
        {
            
            txtPwd.Focus();
        }

        #endregion


    }
    public class TransTextBox : RichTextBox
    {
        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
        static extern IntPtr LoadLibrary(string lpFileName);

        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams prams = base.CreateParams;
                if (LoadLibrary("msftedit.dll") != IntPtr.Zero)
                {
                    prams.ExStyle |= 0x020; // transparent
                    prams.ClassName = "RICHEDIT50W";// TRANSTEXTBOXW
                }
                return prams;
            }
        }
    }
}
